using System;
using Cinemachine;
using UnityEngine;

namespace Yoozoo.Core.Common
{
    public class FollowOffsetQualityListener : QualityListenerMono<FollowOffsetQualityListener.FollowOffsetQualitySetting>
    {
        [Serializable]
        public class FollowOffsetQualitySetting : QualitySetting
        {
            public Vector3 followOffset;
        }
        
        [SerializeField]
        private CinemachineVirtualCamera _virtualCamera;

        protected override void Awake()
        {
            if (!_virtualCamera)
            {
                _virtualCamera = GetComponent<CinemachineVirtualCamera>();
            }            
        }

        public override void ChangeQualitySetting(FollowOffsetQualitySetting qualitySetting)
        {
            if (_virtualCamera)
            {
                CinemachineTransposer transposer = _virtualCamera.GetCinemachineComponent<CinemachineTransposer>();
                if (transposer)
                {
                    transposer.m_FollowOffset = qualitySetting.followOffset;
                }

            }
        }
    }
}